/**
 * 
 */
package ar.edu.unicen.exa.oop.bbquery.forum_service.crawler;

import java.util.HashMap;

import ar.edu.unicen.exa.oop.bbquery.model.forum.ForumAuthToken;

/**
 * un poco mas y hacemos un container ... nicocontainer ? 
 * @author nicolas
 *
 */

public class DefaultCrawlerFactory implements CrawlerFactory {

    HashMap<String, Class<? extends Crawler>> impls;
    
    public DefaultCrawlerFactory()
    {
	impls =new HashMap<String, Class<? extends Crawler>>();	
    }
    
    public DefaultCrawlerFactory(HashMap<String, Class<? extends Crawler>> f) {
	impls=f;	
    }
    
    /* (non-Javadoc)
     * @see ar.edu.unicen.exa.oop.bbquery.forum_service.crawler.CrawlerFactory#createCrawler(ar.edu.unicen.exa.oop.bbquery.model.forum.ForumAccessToken)
     */
    @Override
    public Crawler createCrawler(ForumAuthToken tkn)
	    throws UnknownForumException {
	Class<? extends Crawler> to_create=impls.get(tkn.getForumTypeString());
	try {
	    Crawler clr= to_create.getConstructor(String.class).newInstance(tkn.getForumRootURL().toString());
	    return clr;
	} catch (Exception e) {
	     throw new UnknownForumException();	
	}
    }

}
